package edu.gxmzu.task.utils;

import java.io.File;
/**
 * author: lrf
 * time: 2024-11-29
 * version : V1
 * detail: 附件上传处理
 * @return
 */
public class FileUtil {

    /**
     * 获取文件名，不包含后缀
     *
     * @param fileName 文件的完整路径
     * @return 文件名
     */
    public static String getFileName(String fileName) {
        File file = new File(fileName);
        String nameWithExtension = file.getName();
        int lastDotIndex = nameWithExtension.lastIndexOf('.');
        return (lastDotIndex == -1) ? nameWithExtension : nameWithExtension.substring(0, lastDotIndex);
    }

    /**
     * 获取文件后缀
     * @param fileName 文件的完整路径
     * @return 文件后缀
     */
    public static String getFileExtension(String fileName) {
        File file = new File(fileName);
        String nameWithExtension = file.getName();
        int lastDotIndex = nameWithExtension.lastIndexOf('.');
        return (lastDotIndex == -1) ? "" : nameWithExtension.substring(lastDotIndex + 1);
    }
    
}
